package edu.yctc.manage.service.impl;

import edu.yctc.manage.dao.StudentDAO;
import edu.yctc.manage.entity.PageDO;
import edu.yctc.manage.entity.StudentDO;
import edu.yctc.manage.service.StudentService;
import edu.yctc.manage.utils.PageQuery;
import edu.yctc.manage.utils.VOUtil;
import edu.yctc.manage.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service("studentService")
public class StudentServiceImpl implements StudentService {

    @Autowired
    private VOUtil voUtil;

    @Resource
    private StudentDAO studentDAO;

    @Override public PageDO getVOList(PageQuery pageQuery) {
        List<StudentVO> studentVOS = voUtil.StudentDOs2VOs(studentDAO.selectList(pageQuery));
        int total = studentDAO.getTotal();
        return new PageDO(total, pageQuery.getLimit(), pageQuery.getPage(), studentVOS);

    }

    @Override public int saveStudent(StudentDO studentDO) {
        return studentDAO.insert(studentDO);
    }

    @Override public int update(StudentDO studentDO) {
        return studentDAO.update(studentDO);
    }

    @Override public int delete(Long[] ids) {
        return studentDAO.deleteBatchIds(Arrays.asList(ids));
    }
}